FROM daocloud.io/library/php:7.0-fpm

ADD sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y \
        git \
        wget \
        vim \
        libgearman-dev \
        libmemcached-dev \
        libmcrypt-dev \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng12-dev \
        libcurl4-gnutls-dev \
        libjpeg-dev \
        libpng-dev \
        libxpm-dev \
        libxslt1-dev \
        libxml2-dev \
        alien \
        cron

# php-src/ext install
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
        && docker-php-ext-install zip \
        && docker-php-ext-install gd \
        && docker-php-ext-install pdo_mysql

# pecl install
RUN pecl install redis && echo 'redis.so' > /usr/local/etc/php/conf.d/redis.ini

# PHP conf
ADD php-env.ini /usr/local/etc/php/conf.d/zzz_php-env.ini
ADD php-fpm-env.conf /usr/local/etc/php-fpm.d/zzz-fpm-env.conf

# crontab
ADD crontabs/root /var/spool/cron/crontabs/root
RUN chown -R root:crontab /var/spool/cron/crontabs/root \
 && chmod 600 /var/spool/cron/crontabs/root
RUN mkdir -p /alidata/log &&  touch /alidata/log/cron.log

ADD tools/phpunit-5.5.5.phar /usr/local/bin/phpunit 
RUN chmod +x /usr/local/bin/phpunit

RUN git clone https://github.com/php-memcached-dev/php-memcached.git /alidata/php-memcached
WORKDIR /alidata/php-memcached
RUN git checkout php7
RUN phpize
RUN ./configure --disable-memcached-sasl
RUN make
RUN make install
RUN echo 'memcached.so' > /usr/local/etc/php/conf.d/memcached.ini

WORKDIR /alidata/www

# init cmd
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
CMD /entrypoint.sh
